app.controller('LoginController', ['$scope', '$timeout', '$http', '$compile', 'toaster', '$location', '$modal', 'R', 'FileUploader', '$q', '$state', '$rootScope',
function($scope, $timeout, $http, $compile, toaster, $location, $modal, R, FileUploader, $q, $state, $rootScope) {
    
    $scope.user = {
        account: '',
        pwd: ''
    };

    var user = $rootScope.getSgObj('LOGINUSER');
    if (user){
        $state.go('app.product.list');
    }

    $scope.login = function() {
      $scope.authError = null;

      R.login({account: $scope.user.account, pwd: md5($scope.user.pwd)})
      .then(function(data) {
        if ( data.rtnCode != '0000000' ) {
          $scope.authError = data.msg;
        }else{
          $rootScope.setSgObj('LOGINUSER', data.bizData);
          $state.go('app.product.list');
        }
      });
    };

}]);